package com.lee;

import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.Part;
import java.io.IOException;
import java.util.Collection;

@WebServlet("/upload")
@MultipartConfig  //如果不加这个注解，Tomcat不会解析Multipart 内容
public class UploadServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String username = req.getParameter("username");
        System.out.println(username);
        String password = req.getParameter("password");
        System.out.println(password);
        
        Collection<Part> parts = req.getParts();
        for(Part part:parts){
            System.out.println("=========================================");
            System.out.println(part.getName());
            System.out.println(part.getContentType());
            Collection<String> headers=part.getHeaderNames();
            for(String header:headers){
                System.out.println(part.getHeader(header));
            }
            System.out.println(part.getSize());
            System.out.println(part.getSubmittedFileName());
        }
    }
}
